package com.bdq.search.infrastructure.persistence.mysql.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdq.common.enums.YesOrNoEnum;
import com.bdq.search.infrastructure.persistence.mysql.mapper.SearchHistoryMapper;
import com.bdq.search.infrastructure.persistence.mysql.pojo.SearchHistory;
import com.bdq.search.infrastructure.persistence.mysql.service.SearchHistoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author malei
* @description 针对表【search_history(搜索历史表)】的数据库操作Service实现
* @createDate 2024-05-26 16:57:09
*/
@Service
public class SearchHistoryServiceImpl extends ServiceImpl<SearchHistoryMapper, SearchHistory>
    implements SearchHistoryService{

    @Override
    public Boolean deleteSearchHistory(Long userId, String keyword) {
        return lambdaUpdate()
                .set(SearchHistory::getIsDeleted, YesOrNoEnum.YES.getCode())
                .eq(SearchHistory::getUserId, userId)
                .eq(SearchHistory::getContent, keyword)
                .eq(SearchHistory::getIsDeleted, YesOrNoEnum.NO.getCode())
                .update();
    }

    @Override
    public List<SearchHistory> listByUserId(Long userId) {
        return lambdaQuery()
                .eq(SearchHistory::getUserId, userId)
                .eq(SearchHistory::getIsDeleted, YesOrNoEnum.NO.getCode())
                .orderByDesc(SearchHistory::getId)
                .list();
    }

    @Override
    public Boolean deleteByUserId(Long userId) {
        return lambdaUpdate()
                .set(SearchHistory::getIsDeleted, YesOrNoEnum.YES.getCode())
                .eq(SearchHistory::getUserId, userId)
                .update();
    }

    @Override
    public Boolean deleteBatchByIds(List<Long> deleteIds) {
        return lambdaUpdate()
                .set(SearchHistory::getIsDeleted, YesOrNoEnum.YES.getCode())
                .in(SearchHistory::getId, deleteIds)
                .update();
    }
}




